import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/yb_chinese_text/yb_chinese_text.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBWorkTaiModel/YBWorkTaiReMenModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBWorkTaiModule/YBFenXiangHuKePage/YBBaseProvider/YBBaseProvider.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBWorkTaiModule/YBWorkTaiGongGaoPage/YBWorkTaiGongGaoSubPage/YBWorkTaiGongGaoSubPage.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBWorkTaiModule/YBWorkTaiGongGaoPage/YBWorkTaiGonggaoProvider/YBWorkTaiGongGaoProvider.dart';

enum YBWorkTaiGongGaoMainType {
  YBGonggao,
  YBKuaiXun,
  YBReMen,
}

class YBWorkTaiGongGaoMainPage extends StatelessWidget {

  final YBWorkTaiGongGaoMainType gongGaoMainType;



  const YBWorkTaiGongGaoMainPage({Key key, this.gongGaoMainType}) : super(key: key);


  @override
  Widget build(BuildContext context) {

    String typeStr;
    String titleStr;
    if (gongGaoMainType == YBWorkTaiGongGaoMainType.YBGonggao) {
        typeStr = "ybapp_ptgg";
        titleStr = YBChineseText.workTaiGongGaoTitle;
    }else if (gongGaoMainType == YBWorkTaiGongGaoMainType.YBKuaiXun) {
        typeStr = 'kuaixun';
        titleStr = YBChineseText.workTaiKuaiXunTitle;
    }else if (gongGaoMainType == YBWorkTaiGongGaoMainType.YBReMen){
        typeStr = 'material_library';
        titleStr = YBChineseText.workTaiReMenTitle;
    }

    return ChangeNotifierProvider(
        create: (context) => YBBaseProvider()..getReMenDataList(1,typeStr),
        child: Container(
          color: YBColor.white,
          child: Scaffold(
            appBar: AppBar(
              title: Container(
                child: Text(titleStr,style:YBTextStyle.TextStyle30313320Medium,),
              ),
              elevation: 0,
            ),
            body:Consumer<YBBaseProvider>(
                builder:(context, gongGaoInfo,child){

                  return SmartRefresher(
                    controller:gongGaoInfo.easyRefreshController,
                    onLoading:() async {
                      gongGaoInfo.loadData(typeStr);
                    },
                    enablePullUp: true,
                    enablePullDown: true,
                    onRefresh: () async {
                      gongGaoInfo.refreshData(typeStr);
                    },
                    child:CustomScrollView(
                      slivers: [
                        SliverList(
                          delegate: SliverChildBuilderDelegate(
                                (context, index){
                              YBWorkTaiRemenModel gongGaoModel = gongGaoInfo.reMenModelList[index];
                              print('id==========${gongGaoModel.id}');
                              if (gongGaoMainType == YBWorkTaiGongGaoMainType.YBGonggao) {
                                return YBWorkTaiGongGaoSubPage(title: gongGaoModel.title,subTitle: gongGaoModel.subTitle,idstr:gongGaoModel.id.toString(),);
                              }else if (gongGaoMainType == YBWorkTaiGongGaoMainType.YBKuaiXun) {
                                return YBWorkTaiGongGaoSubPage(title: gongGaoModel.title,subTitle: gongGaoModel.subTitle,idstr:gongGaoModel.id.toString(),createTime: gongGaoModel.createTime,);
                              }else if (gongGaoMainType == YBWorkTaiGongGaoMainType.YBReMen){
                                return YBWorkTaiGongGaoSubPage(title: gongGaoModel.title,subTitle: gongGaoModel.subTitle,idstr:gongGaoModel.id.toString(),);
                              }else{
                                return YBWorkTaiGongGaoSubPage(title: gongGaoModel.title,subTitle: gongGaoModel.subTitle,idstr:gongGaoModel.id.toString(),);
                              }

                            },
                            childCount: gongGaoInfo.reMenModelList.length,
                          ),
                        ),
                      ],
                    ),
                  );
             }),
          ),
        ),
    );
  }
}
